﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.Model.Enum;

namespace HZ.DrugTrade.Web.Admin.RelationQuery
{
    public partial class ComapnyUpdateArea : BasePage
    {
        public ComapnyUpdateArea()
        {
            this.ModuleNo = Module.配送关系管理.ToString();
            this.PageOperateType = OperateType.配送区域新增.ToString();
        }
        IBLL_Area iarea = Factory.BLL_Area();
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                Bind();
            }
        }

        public void Bind()
        {
            string where = "";
            int totalRecord = 0;
            if (!string.IsNullOrEmpty(txtcompanyid.Text.Trim()))
            {
                where += " and companyid = '" + txtcompanyid.Text.Trim() + "'";
            }
            if (!string.IsNullOrEmpty(txtcompanyname.Text.Trim()))
            {
                where += " and companyname = '" + txtcompanyname.Text.Trim() + "'";
            }
            DataTable dt = iarea.GetCompanyAreaidByCompanyid(where,this.AspNetPager1.CurrentPageIndex,this.AspNetPager1.PageSize, out totalRecord);
            this.AspNetPager1.RecordCount = totalRecord;
            GvRelaion.DataSource = dt;
            GvRelaion.DataBind();
        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            string where = "";
            int totalRecord = 0;
            if (!string.IsNullOrEmpty(txtcompanyid.Text.Trim()))
            {
                where += " and companyid = '" + txtcompanyid.Text.Trim() + "'";
            }
            if (!string.IsNullOrEmpty(txtcompanyname.Text.Trim()))
            {
                where += " and companyname = '" + txtcompanyname.Text.Trim() + "'";
            }
            DataTable dt = iarea.GetCompanyAreaidByCompanyid(where,1, 0, out totalRecord);
            HZ.Excel.ExcelHelper.ExportDataForWeb(dt, GvRelaion);
        }

        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            Bind();
        }
    }
}